<?php


namespace app\api\validate;


use think\Validate;

class UserValidate extends Validate
{
    // 定义验证规则
    protected $rule = [
        'user_name' => 'max:20|requireIf:account_type,2',
        'school_name' => 'max:50|requireIf:account_type,2',
        'school_address' => 'max:255|requireIf:account_type,2',
        'mobile' => 'require|mobile',  //unique:user
        'password' => 'require',
        'account_type' => 'require|integer',
    ];

    // 定义验证失败时的提示信息
    protected $message = [
        'user_name.require' => '用户名不能为空',
        'mobile.unique:user' => '手机号已存在',
    ];

    // 验证场景
    protected  $scene = [
        'register' => ['user_name','school_name','school_address','mobile','password','account_type','status'],
        'login' => ['mobile','password'],
    ];
}